//
// Created by wirano on 2021/4/1.
//
/*
#include "Ano_USB.h"

#include "Ano_DT.h"
#include "Ano_USB.h"
#include "usbd_custom_hid_if.h" //包括发送函数头文件

extern USBD_HandleTypeDef hUsbDeviceFS; //外部声明USB的句柄

uint8_t HID_SEND_TIMEOUT = 5;            //hid发送不足一帧时，等待HID_SEND_TIMEOUT周期进行发送
uint8_t hid_datatemp[256];                    //hid环形缓冲区
uint8_t hid_datatemp_begin = 0;        //环形缓冲区数据指针，指向应当发送的数据
uint8_t hid_datatemp_end = 0;            //环形缓冲区数据结尾
uint8_t hid_data2send[64];                    //hid发送缓存，一个hid数据帧64字节，第一字节表示有效数据字节数，0-63，后面是数据，最多63字节

void Usb_Hid_Init(void)
{
//    usbd_init();
//    usbd_connect(__TRUE);
}

void Usb_Hid_Adddata(uint8_t *dataToSend, uint8_t length)
{
    for (uint8_t i = 0; i < length; i++)
    {
        hid_datatemp[hid_datatemp_end++] = dataToSend[i];
    }
}

void Usb_Hid_Send(void)
{
    static uint8_t notfull_timeout = 0;

    if (hid_datatemp_end > hid_datatemp_begin)
    {
        if ((hid_datatemp_end - hid_datatemp_begin) >= 63)
        {
            notfull_timeout = 0;
            hid_data2send[0] = 63;
            for (uint8_t i = 0; i < 63; i++)
            {
                hid_data2send[i + 1] = hid_datatemp[hid_datatemp_begin++];
            }
//            usbd_hid_get_report_trigger(0, hid_data2send, 64);		//send
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, hid_data2send, sizeof(hid_data2send));
        } else
        {
            notfull_timeout++;
            if (notfull_timeout == HID_SEND_TIMEOUT)
            {
                notfull_timeout = 0;
                hid_data2send[0] = hid_datatemp_end - hid_datatemp_begin;
                for (uint8_t i = 0; i < 63; i++)
                {
                    if (i < hid_datatemp_end - hid_datatemp_begin)
                        hid_data2send[i + 1] = hid_datatemp[hid_datatemp_begin + i];
                    else
                        hid_data2send[i + 1] = 0;
                }
                hid_datatemp_begin = hid_datatemp_end;
//                usbd_hid_get_report_trigger(0, hid_data2send, 64);        //send
                USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, hid_data2send, sizeof(hid_data2send));
            }
        }
    } else if (hid_datatemp_end < hid_datatemp_begin)
    {
        if ((256 - hid_datatemp_begin + hid_datatemp_end) >= 63)
        {
            notfull_timeout = 0;
            hid_data2send[0] = 63;
            for (uint8_t i = 0; i < 63; i++)
            {
                hid_data2send[i + 1] = hid_datatemp[hid_datatemp_begin++];
            }
//            usbd_hid_get_report_trigger(0, hid_data2send, 64);        //send
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, hid_data2send, sizeof(hid_data2send));
        } else
        {
            notfull_timeout++;
            if (notfull_timeout == HID_SEND_TIMEOUT)
            {
                notfull_timeout = 0;
                hid_data2send[0] = 256 - hid_datatemp_begin + hid_datatemp_end;
                for (uint8_t i = 0; i < 63; i++)
                {
                    if (i < 256 - hid_datatemp_begin + hid_datatemp_end)
                        hid_data2send[i + 1] = hid_datatemp[(uint8_t) (hid_datatemp_begin + i)];
                    else
                        hid_data2send[i + 1] = 0;
                }
                hid_datatemp_begin = hid_datatemp_end;
//                usbd_hid_get_report_trigger(0, hid_data2send, 64);        //dend
                USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, hid_data2send, sizeof(hid_data2send));
            }
        }
    }
}

//int usbd_hid_get_report(uint8_t rtype, uint8_t rid, uint8_t *buf, uint8_t req)
//{
//    switch (rtype)
//    {
//        case HID_REPORT_INPUT:
//            switch (rid)
//            {
//                case 0:
//                    switch (req)
//                    {
//                        case USBD_HID_REQ_EP_CTRL:
//                        case USBD_HID_REQ_PERIOD_UPDATE:
//                            return 64;
//                        case USBD_HID_REQ_EP_INT:
//                            break;
//                    }
//                    break;
//            }
//            break;
//        case HID_REPORT_FEATURE:
//            return (1);
//    }
//    return (0);
//}
//
//void usbd_hid_set_report(uint8_t rtype, uint8_t rid, uint8_t *buf, int len, uint8_t req)
//{
//
//    switch (rtype)
//    {
//        case HID_REPORT_OUTPUT:
//            for (uint8_t i = 1; i <= (*(buf)); i++)
//                ANO_DT_Data_Receive_Prepare(*(buf + i));        //hid接收到数据会调用此函数
//            break;
//        case HID_REPORT_FEATURE:
//            //feat = buf[0];
//            break;
//    }
//}
*/
